

module.exports = function ($resource, $state, $http, FileUploader, toaster) {

	return {

		restrict: 'AE',
		template: require('../views/creategroup.html'),
		replace: true,
		scope: {
			'saleobj': '=',
			'funobj': '=',
			'baseinfo': '=',
			'util': '=',
		},
		link: function (scope, elements, attrs) {
      console.log('----------util------------')
      scope.infolist = []
      var info = {}
      scope.info = info
      
      var para = {}
      /* 修改数据处理 */
      var updlist = []
      scope.upd = function(id){
        var upddata = {}
        updata = scope.infolist[id]
        updlist.splice(id,1,updata);
      }
      /* 准备传参数组para */
      para = {
        'info': scope.info,
        'infolist' : scope.infolist
        // 'updlist' : updlist
      }
      scope.save = function() {
        scope.info.start_time = scope.util.date2str(scope.time.date._d)
        console.log(para);
        $resource('/api/ac/ggc/tourGroupAfter/createTourGroup', {}, {}).save(para,function (res) {
          if(res.errcode !== 0){
            toaster.error({ title: "提示", body: res.errmsg });
          }else{
            scope.saleobj.tourgroup_code = res.data[0].tourgroup_code
            console.log(scope.saleobj.tourgroup_code);
          }
        });
      }
      scope.time = {
        'date' : '',
        'options' : {
            //  format: "YYYY-MM-DD",
            locale : 'zh-cn',
            showClear: true  ,
            //  clearBtn:true
        }
      }
      scope.add = function() {
        
        scope.infolist.push({
          center_name : '',
          center_log : '',
          center_lat : '',
          center_no: ''
        })
        scope.remove = function (index) {
          scope.infolist.splice(index, 1);
      }
    }



      }
        }
    }